merge m:1 Country_string Year using "/Users/Karsten/Documents/Projekter/2. Structural Conditions/8. Submission 2020/swiid8_2/stata_swiid.dta"
merge m:1 Country_string Year using "/Users/Karsten/Documents/Projekter/2. Structural Conditions/8. Submission 2020/swiid8_2/Government_Debt_GDP.dta"
merge m:1 Country_string Year using "/Users/Karsten/Documents/Projekter/2. Structural Conditions/8. Submission 2020/Government_Deficit to GDP.dta"
merge m:1 Country_string Year using "/Users/Karsten/Documents/Projekter/2. Structural Conditions/8. Submission 2020/swiid8_2/SWIID new control variables.dta"

sum gini_disp gini_disp_dev_point gini_disp_dev_pct Years_membership Government_debtGDP
gen std_gini_disp=(gini_disp-29.39005)/3.512396
gen std_gini_disp_dev_point=(gini_disp_dev_point-.0428454)/.2657962
gen std_gini_disp_dev_pct=(gini_disp_dev_pct-.161207)/.9435628
gen std_Years_membership=(Years_membership-22.60397)/19.49336
gen std_Government_debtGDP=(Government_debtGDP-61.43285)/34.78445
gen std_Government_deficit_pctofGDP=(Government_deficit_pctofGDP+3.149333)/3.858178
sum lr_scale demo_education_cat3 demo_alder_cat4 demo_female demo_commtype if nomiss_1==1

sum GDP GDP_growth Unemployment Inflation GOV_revenue P_risk_at P_risk_bt P_risk_reduc Population Immigrants_pop GINI GINI_point GINI_pct QUINT QUINT_point QUINT_pct gini_disp gini_disp_dev_point gini_disp_dev_pct if nomiss_1==1
gen std_GDP=(GDP-26417.12)/15013.54
gen std_GDP_growth=(GDP_growth-1.025359)/.0753519
gen std_Unemployment=(Unemployment-8.537992)/4.151288
gen std_Inflation=(Inflation-2.095337)/2.234309
gen std_GOV_revenue=(GOV_revenue-45.84099)/6.376027
gen std_P_risk_at=(P_risk_at-16.09226)/3.87599
gen std_P_risk_bt=(P_risk_bt-22.62117)/5.418703
gen std_P_risk_reduc=(P_risk_reduc-.2851572)/.0689433
gen std_Immigrants_pop=(Immigrants_pop-.8513167)/.6707905
gen std_GINI=(GINI-29.6551)/3.841209
gen std_GINI_point=(GINI_point+.0383256)/1.23285
gen std_GINI_pct=(GINI_pct-.0126796)/4.037367
gen std_QUINT=(QUINT-4.975914)/1.274437
gen std_QUINT_point=(QUINT_point+.0035729)/.4287695
gen std_QUINT_pct=(QUINT_pct-.3343615)/7.733322

gen std_gini_disp=(gini_disp-29.24667)/3.494361
gen std_gini_disp_dev_point=(gini_disp_dev_point-.0404756)/.2336075
gen std_gini_disp_dev_pct=(gini_disp_dev_pct-.1468227)/.8249807


gen std_gini_disp_3=.
replace std_gini_disp_3=1 if std_gini_disp<=-0.5
replace std_gini_disp_3=2 if std_gini_disp>=-0.49999999999999 & std_gini_disp<=0.49999999999999
replace std_gini_disp_3=3 if std_gini_disp>=0.5
gen std_GINI_3=.
replace std_GINI_3=1 if std_GINI<=-0.5
replace std_GINI_3=2 if std_GINI>=-0.49999999999999 & std_GINI<=0.49999999999999
replace std_GINI_3=3 if std_GINI>=0.5
sum std_QUINT if nomiss_1==1
gen std_QUINT_3=.
replace std_QUINT_3=1 if std_QUINT<=-.5
replace std_QUINT_3=2 if std_QUINT>=-.49999999999999 & std_QUINT<=.49999999999999
replace std_QUINT_3=3 if std_QUINT>=.5

mark nomiss_1
markout nomiss_1 EUsupport lr_scale QUINT_3 QUINT_point std_GDP std_GDP_growth std_Unemployment std_Inflation ///
std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP ///
std_Government_deficit_pctofGDP timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype Year country


bysort country: egen L2_weight=mean(weight_eu28)

****************************************************************************************************************
*** - GINI + pct-points ********************** THIS FOR TABLE 1 ************************************************
****************************************************************************************************************

*Model 1
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale std_GINI std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
*Model 2
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI_point std_GINI ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*Visualisation
	quietly margins, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1, replace)
*Model 3
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*Visualisation
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.GINI_point ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	margins std_gini_disp_3, dydx(std_gini_disp_dev_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1a, replace)
* MODEL 4
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*** VISUALIZATION
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.std_GINI_point ///
	std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	quietly margins std_GINI_3, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins2a, replace)
****************************************************************************************************************
****************************************************************************************************************
****************************************************************************************************************

*************** *************** *************** **************** *************** *************** ***************
*************** *************** *************** Robustness check *************** *************** ***************
*************** *************** *************** **************** *************** *************** ***************

*** - OLOGIT: GINI + pct-points ********************** THIS FOR TABLE X ************************
*Model 1
ologit EUsupport_int2 c.lr_scale##c.lr_scale std_GINI std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
*Model 2
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI_point std_GINI ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
	*Visualisation
	quietly margins, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1, replace)
*Model 3
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
	*Visualisation
	quietly meologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.GINI_point ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
	margins std_gini_disp_3, dydx(std_gini_disp_dev_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1a, replace)
* MODEL 4
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
	*** VISUALIZATION
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.std_GINI_point ///
	std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1
	quietly margins std_GINI_3, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins2a, replace)
	
	
*** - LOGIT: GINI + pct-points ********************** THIS FOR TABLE X ************************
*Model 1
xtmelogit EUsupport c.lr_scale##c.lr_scale std_GINI std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
*Model 2
xtmelogit EUsupport c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI_point std_GINI ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*Visualisation
	quietly margins, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1, replace)
*Model 3
xtmelogit EUsupport c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
*MODEL 4
xtmelogit EUsupport c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*** VISUALIZATION
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.std_GINI_point ///
	std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	quietly margins std_GINI_3, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins2a, replace)
	
*** - OLOGIT (ROBUST): GINI + pct-points ********************** THIS FOR TABLE X ************************
*Model 1
ologit EUsupport_int2 c.lr_scale##c.lr_scale std_GINI std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1, robust
*Model 2
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI_point std_GINI ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1, robust
	*Visualisation
	quietly margins, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1, replace)
*Model 3
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1, robust
* MODEL 4
ologit EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1, robust
	*** VISUALIZATION
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_GINI_3##c.std_GINI_point ///
	std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year i.country if nomiss_1==1, robust
	quietly margins std_GINI_3, dydx(std_GINI_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins2a, replace)
	
*** - QUINTILE + pct-points ********************** THIS FOR TABLE A5 *******************
*Model 1
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale std_QUINT std_QUINT_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
*Model 2
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_QUINT_point std_QUINT ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*Visualisation
	quietly margins, dydx(std_QUINT_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins1, replace)
*Model 3
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_QUINT##c.std_QUINT_point ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
* MODEL 4
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_QUINT##c.std_QUINT_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	*** VISUALIZATION
	quietly xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##i.std_QUINT_3##c.std_QUINT_point ///
	std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
	timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype i.Year if nomiss_1==1 || country:
	quietly margins std_QUINT_3, dydx(std_QUINT_point) at(lr_scale=(1(1)10))
	marginsplot, recast(line) recastci(rarea) name(margins2b, replace)

	
*** - Testing with adjustment for income ********************** THIS FOR TABLE AX *******************

mark nomiss_income
markout nomiss_income nomiss_1 income_diffpaying

* MODEL 4 - without income
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype income_diffpaying i.Year if nomiss_income==1 || country:
* MODEL 4 - with income
xtmixed EUsupport_int2 c.lr_scale##c.lr_scale c.lr_scale##c.std_GINI##c.std_GINI_point ///
std_GDP std_GDP_growth std_Unemployment std_Inflation std_GOV_revenue std_P_risk_at std_P_risk_reduc std_Immigrants_pop std_Years_membership std_Government_debtGDP std_Government_deficit_pctofGDP ///
timevar i.demo_education_cat3 i.demo_alder_cat4 i.demo_female i.demo_commtype income_diffpaying i.Year if nomiss_income==1 || country:




